package cn.raven.basic.service.impl;

import cn.raven.basic.mapper.BaseMapper;
import cn.raven.basic.query.BaseQuery;
import cn.raven.basic.service.IBaseService;
import cn.raven.basic.utils.PageList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**

* @Description: 部门管理业务层
* @Author: king
* @Version: 1.0
* @Date:  2022/6/21 17:51
  */
//只读事务
@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class BaseServiceImpl<T> implements IBaseService<T> {
    @Autowired
    private BaseMapper<T> baseMapper;
    /**
    * @Title: findAll
    * @Description: 查询所有
    * @Author: king
    * @Version: 1.0
    * @Date:  2022/6/21 17:11
    * @Parameters: []
    * @Return java.util.List<cn.raven.org.domain.T>
      */
    @Override
    public List<T> findAll() {
        return baseMapper.findAll();
    }

    /**
    * @Title: findOne
    * @Description: 根据id查询
    * @Author: king
    * @Version: 1.0
    * @Date:  2022/6/21 17:11
    * @Parameters: [id]
    * @Return cn.raven.org.domain.T
      */
    @Override
    public T findOne(Long id) {
        return baseMapper.findOne(id);
    }
    
    /** 
    * @Title: add
    * @Description: 新增
    * @Author: Mr.She
    * @Version: 1.0
    * @Date:  2022/6/21 17:09  
    * @Parameters: [t]
    * @Return void
      */
    @Override
    @Transactional
    public void add(T t) {
        baseMapper.add(t);
    }

    /**
    * @Title: update
    * @Description: 更新
    * @Author: king
    * @Version: 1.0
    * @Date:  2022/6/21 17:43
    * @Parameters: [t]
    * @Return void
      */
    @Override
    @Transactional
    public void update(T t) {
        baseMapper.update(t);
    }
    /**
    * @Title: del
    * @Description: 删除
    * @Author: king
    * @Version: 1.0
    * @Date:  2022/6/21 17:51
    * @Parameters: [id]
    * @Return void
      */
    @Override
    @Transactional
    public void del(Long id) {
        baseMapper.del(id);
    }
    /**
    * @Title: queryData
    * @Description: 分页+高级查询
    * @Author: king
    * @Version: 1.0
    * @Date:  2022/6/21 17:51
    * @Parameters: [tQuery]
    * @Return cn.raven.basic.utils.PageList<cn.raven.org.domain.T>
      */
    @Override
    public PageList<T> queryData(BaseQuery baseQuery) {
        //查询总条数
        Integer total = baseMapper.queryCount(baseQuery);//
        //查询当前页数据
        List<T> rows = baseMapper.queryData(baseQuery);
        return new PageList<T>(total,rows);
    }
    
    /** 
    * @Title: batchDel
    * @Description: 批量删除
    * @Author: king
    * @Version: 1.0
    * @Date:  2022/6/25 12:29
    * @Parameters: [ids]
    * @Return void
      */
    @Override
    public void batchDel(Long[] ids) {
        baseMapper.batchDel(ids);
    }
    
}
